import java.util.LinkedList;


public class History {
	public enum ActionType{
		ADD, EDIT, DELETE		
	}
	
	public static final int LIMIT = 50;
	private LinkedList<Action> undoStack;
	private LinkedList<Action> redoStack;
	
	public History(){
		undoStack = new LinkedList<Action>();
		redoStack = new LinkedList<Action>();
	}
	
	public void pushUndoStack(Action action){
		if(undoStack.size() >= LIMIT){
			undoStack.removeFirst();
		}
		undoStack.addLast(action);
	}
	
	public void pushRedoStack(Action action){
		if(redoStack.size() >= LIMIT){
			redoStack.removeFirst();
		}
		redoStack.addLast(action);
	}
	
	public Action popUndoStack(){
		if(undoStack.size() > 0){
			return undoStack.removeLast();
		}
		
		return null;
	}
	
	public Action popRedoStack(){
		if(redoStack.size() > 0){
			return redoStack.removeLast();			
		}
		return null;		
	}
	
	public void undo(){
		Action currAction = popUndoStack();
		switch(currAction.getActionType()){
			case ADD:
				//call delete on currAction.getItem();
				//pushRedoStack(currAction);
			
				break;
			
			case EDIT:
				//int index = currAction.getItem().getIndex();
				//Item edited = item with index				
				//pushRedoStack(new Action(EDIT, edited));
				//change the content of edited to currAction.getItem();
				break;
			
			case DELETE:
				//call add on currAction.getItem();
				//pushRedoStack(currAction);
				
				break;
		}
		
	}

	public void redo(){
		Action currAction = popRedoStack();
		switch(currAction.getActionType()){
			case ADD:
				//call add on currAction.getItem();
				//pushUndoStack(currAction);
			
				break;
			
			case EDIT:
				//int index = currAction.getItem().getIndex();
				//Item beforeEdited = item with index				
				//pushUndoStack(new Action(EDIT, beforeEdited));
				//change the content of beforeEdited to currAction.getItem();
				break;
			
			case DELETE:
				//call delete on currAction.getItem();
				//pushUndoStack(currAction);
				
				break;
		}
		
	
	}
}
